package cn.lanqiao.springboot.controller;

import cn.lanqiao.springboot.service.MenuService;
import cn.lanqiao.springboot.util.CurrentUserUtil;
import cn.lanqiao.springboot.util.Result;
import cn.lanqiao.springboot.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    MenuService menuService;

    @Autowired
    RedisTemplate<String, Object> redisTemplate;

//    @GetMapping("/list")
//    public Result getAllMenus() {
//        UserVO user = (UserVO) CurrentUserUtil.get();
//        List<Menu> menuList = (List<Menu>) redisTemplate.opsForValue().get("menuList:" + user.getRoleId());
//        if(menuList == null){
//            menuList = menuService.selectAllMenus(user.getRoleId());
//            redisTemplate.opsForValue().set("menuList:" + user.getRoleId(), menuList);
//        }
//        return Result.success(menuList);
//    }


    @GetMapping("/list")
    public Result getAllMenus() {
        UserVO user = (UserVO) CurrentUserUtil.get();
        return Result.success(menuService.selectAllMenus(user.getRoleId()));
    }
}
